import React, { useEffect, useState } from 'react'
import { Select, Space, Input, Table, Switch, } from 'antd';
const { Search } = Input;
import type { ColumnsType } from 'antd/es/table';
import '../../styles/classify.less';
import { getLog } from "@/apis/goodsCategory";
import type { SelectProps } from 'antd';

interface DataType {
    key: React.Key;
    name: string;
    age: number;
    address: string;
    description: string;
}

type Props = {}
let data: [] = [];
const options: SelectProps['options'] = [];

for (let i = 10; i < 36; i++) {
    options.push({
        value: i.toString(36) + i,
        label: i.toString(36) + i,
    });
}

const Draw = (props: Props) => {
    const [dataSource, setDataSource] = useState([])
    const columns: ColumnsType<DataType> = [
        { title: 'ID', dataIndex: '_id', key: '_id' },
        { title: '领取人', dataIndex: ['userId', 'nickname'], key: 'nickname' },
        { title: 'phone', dataIndex: ['userId', 'phone'], key: 'phone' },
        { title: '开始使用时间', dataIndex: 'create_time', key: 'create_time' },
        { title: '获取方式', dataIndex: 'system_data', key: 'system_data',render:(system_data)=>{
            if(system_data==true){
                return '手动领取'
            } else {
                return '后台发放'
            }
        } },
        {
            title: '状态', dataIndex: 'state', key: 'state', render: (state) => {
                if (state == 1) {
                    return '已使用'
                } else {
                    return '未使用'
                }

            }
        }
    ];
    const onSearch = async (value: string) => {
        const res = await getLog({ nickname: value })
        console.log("666", res)
        setDataSource(res.data)
        // fetchData()
    };
    useEffect(() => {
        fetchData()
    }, [])
    const fetchData = async () => {
        const res = await getLog({})
        setDataSource(res.data)
        data = res.data
        console.log("123", res);
    }

    return (
        <div>
            <div className='model'>
                <div className='box'>
                    <div className='up'>
                        <div className='search'>
                            <span className='name'>领取人：</span>
                            <Space direction="vertical">
                                <Search placeholder="请输入领取人" onSearch={onSearch} enterButton />
                            </Space>
                        </div>
                    </div>
                </div>
            </div>
            <Table className='table'
                pagination={{ defaultPageSize: 4 }}
                columns={columns}
                rowKey="_id"
                expandable={{
                    expandedRowRender: (record) => <p style={{ margin: 0 }}>{record.description}</p>,
                    rowExpandable: (record) => record.name !== 'Not Expandable',
                }}
                dataSource={dataSource}
            />
        </div>
    )
}

export default Draw